cmake_minimum_required(VERSION 3.2)
project(matxscript_tensorflow)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# fix tensorflow-python missing some header files
ADD_DEFINITIONS(-DMATX_SCRIPT_TENSORFLOW_PYTHON_MODE)

IF (NOT CMAKE_MATX_TF_COMPILE_FLAGS)
    MESSAGE(STATUS "CMAKE_MATX_TF_COMPILE_FLAGS has not been set, use setup.py to install.")
    RETURN(-1)
ENDIF()
MESSAGE(STATUS "CMAKE_MATX_TF_COMPILE_FLAGS: ${CMAKE_MATX_TF_COMPILE_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_MATX_TF_COMPILE_FLAGS}")

IF (NOT CMAKE_MATX_TF_LIB_PATHS)
    MESSAGE(STATUS "CMAKE_MATX_TF_LIB_PATHS has not been set, use setup.py to install.")
    RETURN(-1)
ENDIF()
MESSAGE(STATUS "CMAKE_MATX_TF_LIB_PATHS: ${CMAKE_MATX_TF_LIB_PATHS}")
FOREACH(MATX_OR_TF_LIB_PATH ${CMAKE_MATX_TF_LIB_PATHS})
    LINK_DIRECTORIES(${MATX_OR_TF_LIB_PATH})
ENDFOREACH()

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/)

SET(CMAKE_CXX_FLAGS "-g -O2 -std=c++14 -fPIC -w -fpermissive -pthread ${CMAKE_CXX_FLAGS}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")

FILE(GLOB_RECURSE MATXSCRIPT_TENSORFLOW_SRCS RELATIVE ${CMAKE_SOURCE_DIR}  "src/*.cc")

SET(BUILD_TARGET matx_tensorflow+tensorflow${CMAKE_TENSORFLOW_VERSION})
ADD_LIBRARY(${BUILD_TARGET} SHARED ${MATXSCRIPT_TENSORFLOW_SRCS})

# Link against MATXScript and TensorFlow
IF (NOT CMAKE_MATX_TF_LIB_NAMES)
    MESSAGE(STATUS "CMAKE_MATX_TF_LIB_NAMES has not been set, use setup.py to install.")
    RETURN(-1)
ENDIF()
MESSAGE(STATUS "CMAKE_MATX_TF_LIB_NAMES: ${CMAKE_MATX_TF_LIB_NAMES}")
FOREACH(MATX_OR_TF_LIB_NAME ${CMAKE_MATX_TF_LIB_NAMES})
    TARGET_LINK_LIBRARIES(${BUILD_TARGET} PUBLIC ${MATX_OR_TF_LIB_NAME})
ENDFOREACH()
